package com.kimehwa.studyboot.zuoalgs;

import lombok.AllArgsConstructor;
import lombok.Data;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author xiaodongguan
 * @description
 * @since 2021-08-11 16:51
 */
public class BaseAlgDemo {
    public static void main(String[] args) {
        // 要熟悉常见集合的算法的api 比如array的移除 以及
        // 老公组
        List<Couple> husbands = new ArrayList<>();
        husbands.add(new Couple(1, "梁山伯"));
        husbands.add(new Couple(2, "牛郎"));
        husbands.add(new Couple(3, "干将"));
        husbands.add(new Couple(4, "工藤新一"));
        husbands.add(new Couple(5, "罗密欧"));

        // 老婆组
        List<Couple> wives = new ArrayList<>();
        wives.add(new Couple(1, "祝英台"));
        wives.add(new Couple(2, "织女"));
        wives.add(new Couple(3, "莫邪"));
        wives.add(new Couple(4, "毛利兰"));
        wives.add(new Couple(5, "朱丽叶"));
        int i = 0;
        // 对数据进行处理，要求输出对应的操作  这种查询贼慢
//        for (Couple husband : husbands) {
//            for (Couple wife : wives) {
//                i++;
//                if (husband.getFamilyId().equals(wife.getFamilyId())) {
//
//                    System.out.println(husband.getUserName() + "爱" + wife.getUserName());
//                }
//            }
//        }
//        System.out.println(i);
        // 这个用10次就行了
        Map<Integer, String> wifeMap = new HashMap<>();
        for (Couple wife : wives) {
            wifeMap.put(wife.getFamilyId(), wife.getUserName());
        }
        for (Couple husband : husbands) {
            if (wifeMap.containsKey(husband.getFamilyId())) {
                System.out.println(husband.getUserName() + "爱" + wifeMap.get(husband.getFamilyId()));
            }
        }
    }

    private static void findAllRequired() {

    }


}


@Data
@AllArgsConstructor
class Couple {

    private Integer familyId;

    private String userName;
}
